﻿Public Class xtf_AMBconfig_producto

    Dim ulg_row As DataRow
    Dim obj_config_producto As cls_config_producto = Nothing

    Public Sub New()
        InitializeComponent()
        AgregarValidaciones()
    End Sub

    Public Overrides Sub CargarObjetos()
    End Sub

    Public Shadows Sub Modificar(ByRef config_producto As cls_config_producto, ByRef listado As Form, ByRef row As DataRow)
        If IsNothing(obj_config_producto) Then
            obj_config_producto = New cls_config_producto
        End If
        obj_config_producto = config_producto
        frm_listado = listado
        ulg_row = row : bbi_imprimir.Enabled = True

        Me.Text = "config_producto - " & obj_config_producto.ToString
        txt_nombre.Text = obj_config_producto.nombre
        txt_descripcion.Text = obj_config_producto.descripcion
        txt_splash.Text = obj_config_producto.splash
        txt_logo.Text = obj_config_producto.logo

        If System.IO.File.Exists(Application.StartupPath & "\" & txt_splash.Text) Then
            pic_splash.Image = Image.FromFile(Application.StartupPath & "\" & txt_splash.Text)
        Else
            pic_splash.Image = Nothing
        End If

        If System.IO.File.Exists(Application.StartupPath & "\" & txt_logo.Text) Then
            pic_logo.Image = Image.FromFile(Application.StartupPath & "\" & txt_logo.Text)
        Else
            pic_logo.Image = Nothing
        End If


        flg_Modificado = False : btn_Guardar.Enabled = False : bbi_guardar.Enabled = False

        Me.Show()
    End Sub

    Public Overrides Function ComprobarDatos() As Boolean
        If Not ControlarValidaciones() Then
            ErrManagerShow("000004", Me)
            Return False
        End If
        Return True
    End Function

    Public Shadows Sub btn_Guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Guardar.Click
        If ComprobarDatos() Then
            obj_config_producto.nombre = txt_nombre.Text
            obj_config_producto.descripcion = txt_descripcion.Text
            obj_config_producto.splash = txt_splash.Text
            obj_config_producto.logo = txt_logo.Text

            obj_config_producto.Modificar()

            flg_Modificado = False : btn_Guardar.Enabled = False : bbi_guardar.Enabled = False
        End If
    End Sub

    Private Sub btn_Cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Cerrar.Click
        If flg_Modificado Then
            bol_comprobarCerrado = False
            Select Case ErrManagerShow("000001", Me)
                Case Windows.Forms.DialogResult.Yes
                    If ComprobarDatos() Then
                        btn_Guardar_Click(Nothing, Nothing)
                    Else
                        Exit Sub
                    End If
                Case Windows.Forms.DialogResult.Cancel : bol_comprobarCerrado = True
                    Exit Sub
            End Select
        End If
        Me.Dispose()
    End Sub

    Private Sub txt_splash_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_splash.Validated
        If System.IO.File.Exists(Application.StartupPath & "\" & txt_splash.Text) Then
            pic_splash.Image = Image.FromFile(Application.StartupPath & "\" & txt_splash.Text)
        Else
            pic_splash.Image = Nothing
        End If
    End Sub

    Private Sub txt_logo_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_logo.Validated
        If System.IO.File.Exists(Application.StartupPath & "\" & txt_logo.Text) Then
            pic_logo.Image = Image.FromFile(Application.StartupPath & "\" & txt_logo.Text)
        Else
            pic_logo.Image = Nothing
        End If
    End Sub
End Class